package com.vinci.wishDemo.controller;


import com.vinci.util.Constants;
import com.vinci.util.JsonObject;
import com.vinci.wishDemo.entity.TbContentAppreciate;
import com.vinci.wishDemo.entity.TbContentTopic;
import com.vinci.wishDemo.entity.TbContentWishList;
import com.vinci.wishDemo.mapper.TbContentTopicMapper;
import com.vinci.wishDemo.service.TbContentTopicService;
import com.vinci.wishDemo.entity.TbContentTopic;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 话题表 前端控制器
 * </p>
 *
 * @author 郭三木
 * @since 2021-12-10
 */
@RestController
@RequestMapping("/wishDemo")
@Slf4j
public class TbContentTopicController {
    @Resource
    private TbContentTopicMapper topicMapper;
    @Autowired
    TbContentTopicService topicService;

    /*
    话题详情查询
     */
    @PostMapping("/querytopList")
    public JsonObject querytopList(String createBy, String beginTime, String endTime) {
        List<TbContentTopic> list = topicService.querytopList(createBy, beginTime, endTime);
        JsonObject object = new JsonObject();
        object.setCode(Constants.OK_COOE);
        object.setMsg("ok");
        object.setCount(list.size());
        object.setData(list);
        return object;
    }

    /*
    下架话题
     */
    @PostMapping("/deltop")
    public JsonObject deltop(String topicId, Model model) {
        JsonObject object = new JsonObject();
        if (topicId == null){
            object.setCode(Constants.FAIL_COOE);
            object.setMsg("不能为空");
            return object;
        }
        //修改状态
        topicService.deltop(topicId);
        //获取当前状态返回给前台
        TbContentTopic topstats = topicService.querystats(topicId);
        model.addAttribute("topstats",topstats);
        object.setCode(Constants.OK_COOE);
        object.setMsg("ok");
        return object;
    }
}

